package com.javafactroy.kunlong.bip.icp.context.connpool.ftpclient;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
//@Scope("prototype")
public class FTPClientPool {
    @Autowired
    FTPClientFactory factory;
    GenericObjectPool<FTPClient> ftpClientPool;

    GenericObjectPool<FTPClient> getFtpClientPool() {
        if (ftpClientPool == null) {
            synchronized (this) {
                if (ftpClientPool == null) {
                    ftpClientPool = new GenericObjectPool<FTPClient>(factory, new GenericObjectPoolConfig());
                }
            }

        }
        return ftpClientPool;
    }

    public FTPClientPool() {


    }

    public FTPClient borrowObject() throws Exception {

        return getFtpClientPool().borrowObject();
    }

    public void returnObject(FTPClient ftpClient) {


        getFtpClientPool().returnObject(ftpClient);

    }
}










